<html>
<head><meta charset="utf-8"><title>Comparing types by ExprIds · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Comparing.20types.20by.20ExprIds.html">Comparing types by ExprIds</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="219221272"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Comparing%20types%20by%20ExprIds/near/219221272" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> ivan770 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Comparing.20types.20by.20ExprIds.html#219221272">(Dec 08 2020 at 15:39)</a>:</h4>
<p>Hi. I'm new to RA development, so there is a question I can't find any answer to - how do I compare types by ExprIds? I'm currently trying to implement <a href="https://github.com/rust-analyzer/rust-analyzer/issues/6739">https://github.com/rust-analyzer/rust-analyzer/issues/6739</a> by checking for missing tail expression, and comparing last statement type with body type.</p>



<a name="219221406"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Comparing%20types%20by%20ExprIds/near/219221406" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Comparing.20types.20by.20ExprIds.html#219221406">(Dec 08 2020 at 15:40)</a>:</h4>
<p>You need to look up its type in the <code>InferenceResult</code></p>



<a name="219228100"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Comparing%20types%20by%20ExprIds/near/219228100" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> ivan770 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Comparing.20types.20by.20ExprIds.html#219228100">(Dec 08 2020 at 16:27)</a>:</h4>
<p>Thanks, it worked! Looks like I have some naive implementation, though it seems to be working <a href="/user_uploads/4715/KT82fNXOA1z-QJOHybH2MxSV/demo.mp4">demo.mp4</a></p>



<a name="219246079"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Comparing%20types%20by%20ExprIds/near/219246079" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> ivan770 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Comparing.20types.20by.20ExprIds.html#219246079">(Dec 08 2020 at 18:49)</a>:</h4>
<p>Can I get some code review please? <a href="https://github.com/ivan770/rust-analyzer/commit/cb66bb8ff9609d4fc3702ac1ed6197802b54e473">https://github.com/ivan770/rust-analyzer/commit/cb66bb8ff9609d4fc3702ac1ed6197802b54e473</a><br>
<a href="/user_uploads/4715/5ZeQlYrObud_VkrICi9t6Fj_/demo2.mp4">demo2.mp4</a></p>



<a name="219246277"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Comparing%20types%20by%20ExprIds/near/219246277" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Comparing.20types.20by.20ExprIds.html#219246277">(Dec 08 2020 at 18:50)</a>:</h4>
<p>neat!</p>



<a name="219248699"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Comparing%20types%20by%20ExprIds/near/219248699" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremy Kolb <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Comparing.20types.20by.20ExprIds.html#219248699">(Dec 08 2020 at 19:10)</a>:</h4>
<p>The code looks pretty good to me. If you submit a PR we can do a proper review.</p>



<a name="219491040"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Comparing%20types%20by%20ExprIds/near/219491040" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> ivan770 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Comparing.20types.20by.20ExprIds.html#219491040">(Dec 10 2020 at 15:51)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span> Hi. Can you help me a bit with that part? <a href="https://github.com/rust-analyzer/rust-analyzer/pull/6769#discussion_r540146705">https://github.com/rust-analyzer/rust-analyzer/pull/6769#discussion_r540146705</a><br>
I can't find any way to obtain ExprStmt, as AstNode casts don't work here because of different kinds.</p>



<a name="219491347"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Comparing%20types%20by%20ExprIds/near/219491347" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Comparing.20types.20by.20ExprIds.html#219491347">(Dec 10 2020 at 15:53)</a>:</h4>
<p>Hm, riiight, good question</p>



<a name="219491392"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Comparing%20types%20by%20ExprIds/near/219491392" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Comparing.20types.20by.20ExprIds.html#219491392">(Dec 10 2020 at 15:53)</a>:</h4>
<p>We don't actually store info about <em>statements</em> in the source map yet</p>



<a name="219491460"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Comparing%20types%20by%20ExprIds/near/219491460" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Comparing.20types.20by.20ExprIds.html#219491460">(Dec 10 2020 at 15:54)</a>:</h4>
<p>I guess that means that we should stick to an <code>ast::Expr</code> here</p>



<a name="219491639"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Comparing%20types%20by%20ExprIds/near/219491639" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Comparing.20types.20by.20ExprIds.html#219491639">(Dec 10 2020 at 15:55)</a>:</h4>
<p>Then, in the fix, where you care getting the <code>;</code>, you can write <code>expr.syntax().parent().and_then(ast::ExprStmt::cast).and_then(|it| it.semicolon_token())</code>.</p>



<a name="219493990"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Comparing%20types%20by%20ExprIds/near/219493990" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> ivan770 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Comparing.20types.20by.20ExprIds.html#219493990">(Dec 10 2020 at 16:11)</a>:</h4>
<p>Thanks, it worked!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>